# 进程、互斥锁
from multiprocessing import Process,Lock

def save_to_file(index,lock):
    with lock:
        with open("test2.log",'a',encoding='utf-8') as f:
            f.write(str(index)+"\n")

if __name__=="__main__":
    process_array=[]
    lock=Lock()
    for i in range(10):
        p=Process(target=save_to_file,args=(i,lock))
        process_array.append(p)
        p.start()
    for p in process_array:
        p.join()
    print("done")
